(function($) {
	//alert('hello');
})(jQuery);

function niceScrollresize( seleter ){
		var seleter = seleter || '.niceScroll';
		$(seleter).getNiceScroll().hide();	
		setTimeout(function(){
			$(seleter).getNiceScroll().resize().show();	
		},800);
		
}

//header
$(document).ready(function(){
	
	$(".niceScroll").niceScroll({
	    touchbehavior:false,
        cursorcolor:"#666",
        cursoropacitymax:1,
        cursorwidth:5,
        cursorborder:"none",
        cursorborderradius:"4px",
        background:"#999",
        //autohidemode:false
	});


	
/*	$(".___sidebar-nav3").niceScroll({
		//autohidemode:false
	});*/
	

	

});
/*dl.dropMenu 下拉菜单
dl.dropMenu {position: relative;}
dl.dropMenu dd{ display:none; position:absolute; }
dl.dropMenu.open dd{ display:block;}
*/
$(function(){
	$('dl.dropMenu').hover(function(){
		$(this).addClass('open');								
	},function(){
		$(this).removeClass('open');
	});

});
/* 边栏菜单 */
;
$(function(){
	var $body =    $('.viewFramework-body');
	var $sidebar = $('.viewFramework-sidebar');
	var $main =    $('.viewFramework-main');
	var $fold =    $('.sidebar-fold');
	var cookie = 'sidebar';
	
	function sidebar_full(){
		$body.removeClass('viewFramework-sidebar-mini').addClass('viewFramework-sidebar-full');	
		$fold.removeClass('icon-fold').addClass('icon-unfold');	
		$.cookie(cookie, 'full');
		$(".sidebar-menu " ).tooltip({disabled: true});

	};
	function sidebar_mini(){
		$body.removeClass('viewFramework-sidebar-full').addClass('viewFramework-sidebar-mini');
		$fold.removeClass('icon-unfold').addClass('icon-fold');	
		$.cookie(cookie, 'mini');
		$(".sidebar-menu " ).tooltip({disabled: false});
	};
	
	$fold.on('click',function(){
		if( $($body).hasClass('viewFramework-sidebar-mini') ){
			sidebar_full();
		}else{
			sidebar_mini();
			
		}
		niceScrollresize();
		
	});
	//默认状态
	if( $.cookie(cookie) == 'mini' ){
		sidebar_mini();	
	}else{
		sidebar_full();	//默认
	};


	
});
/* 边栏菜单 end*/
/* 边栏菜单 - 菜单 展开 与 隐藏  */
;
$(function(){
	$('.sidebar-nav').each(function(){
		var $nav = $(this);	
		var $title = $(this).find('.sidebar-title');
		var cookie = 'sidebar-nav-'+$nav.index();
		var $ul = $nav.find('ul');
		var _get_ul_height = function(){
				var h = 0;	
				$ul.children().each(function(){
					h += $(this).outerHeight(true,true);
				});
				return h;
		}

		var _fold=function(){
			$nav.removeClass('sidebar-nav-unfold').addClass('sidebar-nav-fold');	
			$.cookie(cookie, 'fold');
			

			
			$ul.height(_get_ul_height());
		};
		var _unfold=function(){
			$nav.removeClass('sidebar-nav-fold').addClass('sidebar-nav-unfold');	
			$.cookie(cookie, 'unfold');
		};
		
		$title.on('click',function(){
			if( $nav.hasClass('sidebar-nav-unfold') ){
				_fold();
			}else{
				_unfold();
			}
			
			niceScrollresize();
		});
		//默认状态
		//console.log(cookie , $.cookie(cookie));	
		if( $.cookie(cookie) == 'fold' ){
			_fold();
		}else{
			_unfold();//默认
		};
		
		
	});

/*

*/	

	
});
/* 边栏菜单 end*/

/* 三级菜单 开关 viewFramework-main-fold */
$(function(){
	var $wrap = $('.viewFramework-main');	
	var $left = $('.viewFramework-main-siddbar');
	var $body = $('.viewFramework-main-body');
	var $fold = $('.viewFramework-main-fold');
	var _full = function(){
			$wrap.addClass('viewFramework-main-full');
		}
	var _mini = function(){
			$wrap.removeClass('viewFramework-main-full');
		}
		
	$fold.on('click',function(){
		if( $wrap.hasClass('viewFramework-main-full') ){
			_mini();	
		}else{
			_full();
		}	
		//$(".sidebar-nav3").getNiceScroll().resize();
		niceScrollresize();
	});
	
});
/* 三级菜单 开关 viewFramework-main-fold */

$(function(){
	$dropMenu = $('.dropMenu');
	$dropMenu.each(function(){
		var $this = $(this);
		var $title = $this.find('.dropMenuTitle').first();
		var $body = $this.find('.dropMenuBody').first();
		$title.on('click',function(){
			if($this.hasClass('dropMenuOpen')){
				$this.removeClass('dropMenuOpen').addClass('dropMenuClose');
				$body.height(0);
				
				
			}else{
				$this.removeClass('dropMenuClose').addClass('dropMenuOpen');
				var h = 0;
				$body.children().each(function(){
					h += $(this).outerHeight(true,true);							   
				});
				$body.height(h);
			}
			//$(".sidebar-nav3").getNiceScroll().resize();
			niceScrollresize();
		});
	});
	
});
/* ------------- mainNavA ------------- */
$(function(){
	$('.mainNavA').each(function(){
		$box = $(this);
		$nav = $box.find('li');
		$nav_active = $box.find('li.active');
		$hover_line = $('<div class="hover_line"></div>').appendTo($box);

		$nav.hover(function(){
			$(this).addClass('hover').siblings().removeClass('hover');
			var w = $(this).outerWidth();
			var left = $(this).position().left;
			$hover_line.stop().animate({ width: w ,left:left}, 200 );
		},function(){		
		});
		$box.mouseleave(function(){
			if($nav_active.length){
				$nav_active.addClass('hover').siblings().removeClass('hover');
				var w = $nav_active.outerWidth();
				var left = $nav_active.position().left;
				$hover_line.stop().animate({ width: w ,left:left}, 200 );	
			}
			//console.log('mouseleave');								 
		}).mouseleave();
		
	});	
});
/* ------------- mainNavA end ------------- */
$(function () {
	$(".sidebar-menu" ).tooltip({
		items: " [title]",
		position: {
			my: "left top",
			at: "right+15 top+5",
			using: function( position, feedback ) {
				$( this ).css( position );

				console.log($(this));
			}

		},
		show: { effect: "bounce", duration: 800 } ,
		hide: { effect: "drop", duration: 200 },
		tooltipClass: "ui-tooltip-sidebar-menu",


	}).find('.sidebar-menu-item')
		.on('mouseenter',function(){
			$(this).addClass('hover');
		})
		.on('mouseleave',function(){
			$(this).removeClass('hover');
		});



});
